package com.hisense.hiioc.hismartplate.robot.engine;


import com.hisense.hiioc.hismartplate.constants.RobotConstant;
import com.hisense.hiioc.hismartplate.entity.dto.MesRobot;
import com.hisense.hiioc.hismartplate.robot.context.ChartManager;
import com.hisense.hiioc.hismartplate.robot.factory.DirectiveFactory;
import com.hisense.hiioc.hismartplate.robot.message.RobotResponse;
import com.hisense.hiioc.hismartplate.utils.UUIDGenerator;

import java.util.List;

/**
 * @Auther:biexiande@hisense.com
 * @date:2018/7/3 14:23
 * @des
 */
public class AIMLInputHandler extends AbstractInputHandler  {

    private ChartManager chartManager = null;
    public AIMLInputHandler() {
        super();
        this.chartManager =ChartManager.getInstance();
    }
    @Override
    public void doProcess(MesRobot mesRobot,List<String> directiveList, IInputHander nextHandlelr) {
        String input = mesRobot.getText();
        String sessionId =mesRobot.getSessionid();
        String token = UUIDGenerator.create32Key();
        String aimlResult = chartManager.response(input);
        if(RobotConstant.AIML_NOTFOUND.equals(aimlResult)){
            nextHandlelr.doProcess(mesRobot, directiveList);
        }else if(aimlResult.contains(RobotConstant.AIML_SPLITTER)){
            RobotResponse robotResponse = RobotResponse.buildResponse(aimlResult);
            DirectiveFactory.buildDirectiveFromRobot(directiveList, mesRobot, token, robotResponse, sessionId);
        }else{
            DirectiveFactory.generateTextAndVoiceOutputDirective(directiveList,token,aimlResult,"");
        }
    }
}